home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / printernamecombobox.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.9 KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from ui_utils import *
  6. from base import device
  7. from PyQt4.QtCore import *
  8. from PyQt4.QtGui import *
  9. PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY = 0
  10. PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY = 1
  11. PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX = 2
  12.  
  13. class PrinterNameComboBox(QWidget):
  14.     
  15.     def __init__(self, parent):
  16.         QWidget.__init__(self, parent)
  17.         self.printer_name = ''
  18.         self.device_uri = ''
  19.         self.printer_index = { }
  20.         self.initial_printer = None
  21.         self.updating = False
  22.         self.typ = PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY
  23.         self.initUi()
  24.  
  25.     
  26.     def initUi(self):
  27.         HBoxLayout = QHBoxLayout(self)
  28.         HBoxLayout.setObjectName('HBoxLayout')
  29.         self.NameLabel = QLabel(self)
  30.         self.NameLabel.setObjectName('NameLabel')
  31.         HBoxLayout.addWidget(self.NameLabel)
  32.         SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  33.         HBoxLayout.addItem(SpacerItem)
  34.         self.ComboBox = QComboBox(self)
  35.         sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  36.         sizePolicy.setHorizontalStretch(0)
  37.         sizePolicy.setVerticalStretch(0)
  38.         sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
  39.         self.ComboBox.setSizePolicy(sizePolicy)
  40.         self.ComboBox.setObjectName('ComboBox')
  41.         HBoxLayout.addWidget(self.ComboBox)
  42.         self.NameLabel.setText(self._PrinterNameComboBox__tr('Printer:'))
  43.         self.connect(self.ComboBox, SIGNAL('currentIndexChanged(const QString &)'), self.ComboBox_currentIndexChanged)
  44.  
  45.     
  46.     def setType(self, typ):
  47.         if typ in (PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY, PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY, PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX):
  48.             self.typ = typ
  49.         
  50.  
  51.     
  52.     def setInitialPrinter(self, printer_name):
  53.         self.initial_printer = printer_name
  54.  
  55.     
  56.     def updateUi(self):
  57.         if self.typ == PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY:
  58.             self.NameLabel.setText(self._PrinterNameComboBox__tr('Printer Name:'))
  59.             be_filter = [
  60.                 'hp']
  61.         elif self.typ == PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY:
  62.             self.NameLabel.setText(self._PrinterNameComboBox__tr('Fax Name:'))
  63.             be_filter = [
  64.                 'hpfax']
  65.         else:
  66.             self.NameLabel.setText(self._PrinterNameComboBox__tr('Printer/Fax Name:'))
  67.             be_filter = [
  68.                 'hp',
  69.                 'hpfax']
  70.         self.printers = device.getSupportedCUPSPrinters(be_filter)
  71.         self.printer_index.clear()
  72.         if self.printers:
  73.             if self.initial_printer is None:
  74.                 self.initial_printer = user_conf.get('last_used', 'printer_name')
  75.             
  76.             self.updating = True
  77.             
  78.             try:
  79.                 k = 0
  80.                 for i, p in enumerate(self.printers):
  81.                     self.printer_index[p.name] = p.device_uri
  82.                     self.ComboBox.insertItem(i, p.name)
  83.                     if self.initial_printer is not None and p.name == self.initial_printer:
  84.                         self.initial_printer = None
  85.                         k = i
  86.                         continue
  87.                 
  88.                 self.ComboBox.setCurrentIndex(-1)
  89.             finally:
  90.                 self.updating = False
  91.  
  92.             self.ComboBox.setCurrentIndex(k)
  93.         else:
  94.             self.emit(SIGNAL('PrinterNameComboBox_noPrinters'))
  95.  
  96.     
  97.     def ComboBox_currentIndexChanged(self, t):
  98.         self.printer_name = unicode(t)
  99.         if self.updating:
  100.             return None
  101.         self.device_uri = self.printer_index[self.printer_name]
  102.         user_conf.set('last_used', 'printer_name', self.printer_name)
  103.         self.emit(SIGNAL('PrinterNameComboBox_currentChanged'), self.device_uri, self.printer_name)
  104.  
  105.     
  106.     def __tr(self, s, c = None):
  107.         return qApp.translate('PrinterNameComboBox', s, c)
  108.  
  109.  
  110.